///// DeviceColor /////
    using System;
    using System.Collections.Generic;
    using System.Collections;
    //using System.Linq;
    using System.Text;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;


namespace DeviceColor
{
    class Program
    {
        static void Main(string[] args)
        {
            // Generates a PDF file in which the device colorspace is demonstrated.
            // 
            // @param args:  no arguments needed here

            Console.WriteLine("Chapter 11: example DeviceColor");
            Console.WriteLine("-> Creates a PDF file with device colors");
            Console.WriteLine("   and painted.");
            Console.WriteLine("-> file generated: device_color.pdf");
            // step 1: creation of a document-object
            Document document = new Document();
            try
            {
                // step 2:
                // we create a writer
                PdfWriter writer = PdfWriter.GetInstance(
                    // that listens to the document
                        document,
                    // and directs a PDF-stream to a file
                        new FileStream("device_color.pdf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4:
                PdfContentByte cb = writer.DirectContent;
                cb.SetColorFill(new GrayColor(0));
                cb.Rectangle(36, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(0.125f));
                cb.Rectangle(90, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(0.25f));
                cb.Rectangle(144, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(0.375f));
                cb.Rectangle(198, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(0.5f));
                cb.Rectangle(252, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(0.625f));
                cb.Rectangle(306, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(191));
                cb.Rectangle(360, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(223));
                cb.Rectangle(416, 770, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new GrayColor(255));
                cb.Rectangle(470, 770, 36, 36);
                cb.FillStroke();

                cb.SetGrayFill(0);
                cb.Rectangle(36, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.125f);
                cb.Rectangle(90, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.25f);
                cb.Rectangle(144, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.375f);
                cb.Rectangle(198, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.5f);
                cb.Rectangle(252, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.625f);
                cb.Rectangle(306, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.75f);
                cb.Rectangle(360, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(0.875f);
                cb.Rectangle(416, 716, 36, 36);
                cb.FillStroke();
                cb.SetGrayFill(1);
                cb.Rectangle(470, 716, 36, 36);
                cb.FillStroke();

                cb.SetColorFill(BaseColor.BLACK);
                cb.Rectangle(36, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.BLUE);
                cb.Rectangle(90, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.GREEN);
                cb.Rectangle(144, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.MAGENTA);
                cb.Rectangle(198, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.RED);
                cb.Rectangle(252, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.CYAN);
                cb.Rectangle(306, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.ORANGE);
                cb.Rectangle(360, 662, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(BaseColor.WHITE);
                cb.Rectangle(416, 662, 36, 36);
                cb.FillStroke();

                cb.SetRGBColorFill(0x00, 0x00, 0x00);
                cb.Rectangle(36, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFill(0x00, 0x00, 0xFF);
                cb.Rectangle(90, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFill(0x00, 0xFF, 0x00);
                cb.Rectangle(144, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFill(0x00, 0xFF, 0xFF);
                cb.Rectangle(198, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFillF(1f, 0f, 0f);
                cb.Rectangle(252, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFillF(1f, 0f, 1f);
                cb.Rectangle(306, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFillF(1f, 1f, 0f);
                cb.Rectangle(360, 608, 36, 36);
                cb.FillStroke();
                cb.SetRGBColorFillF(1f, 1f, 1f);
                cb.Rectangle(416, 608, 36, 36);
                cb.FillStroke();

                cb.SetColorFill(new CMYKColor(0x00, 0x00, 0x00, 0x00));
                cb.Rectangle(36, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(0x00, 0x00, 0xFF, 0x00));
                cb.Rectangle(90, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(0x00, 0x00, 0xFF, 0x0F));
                cb.Rectangle(144, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(0x00, 0xFF, 0x00, 0x00));
                cb.Rectangle(198, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(0f, 1f, 0f, 0.5f));
                cb.Rectangle(252, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(1f, 0f, 0f, 0f));
                cb.Rectangle(306, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(1f, 0f, 0f, 0.5f));
                cb.Rectangle(360, 554, 36, 36);
                cb.FillStroke();
                cb.SetColorFill(new CMYKColor(0f, 0f, 0f, 1f));
                cb.Rectangle(416, 554, 36, 36);
                cb.FillStroke();

                cb.SetCMYKColorFill(0x00, 0x00, 0x00, 0x00);
                cb.Rectangle(36, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFill(0x00, 0xFF, 0xFF, 0x00);
                cb.Rectangle(90, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFill(0x00, 0xFF, 0xFF, 0x0F);
                cb.Rectangle(144, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFill(0xFF, 0xFF, 0x00, 0x00);
                cb.Rectangle(198, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFillF(1f, 1f, 0f, 0.5f);
                cb.Rectangle(252, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFillF(1f, 0f, 1f, 0f);
                cb.Rectangle(306, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFillF(1f, 0f, 1f, 0.5f);
                cb.Rectangle(360, 500, 36, 36);
                cb.FillStroke();
                cb.SetCMYKColorFillF(0f, 0f, 0f, 1f);
                cb.Rectangle(416, 500, 36, 36);
                cb.FillStroke();
            }

            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }

            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();

            Console.ReadLine();
        }
    }
}
